package com.taplinker.client.widget;

import java.lang.ref.WeakReference;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taplinker.client.R;

public class LoadImageView extends ImageView {

	private WeakReference<View> view = null;
	private WeakReference<TextView> textView = null;
	public LoadImageView(Context context) {
		super(context);
	}
	
	public LoadImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
    }

    public LoadImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
	public void setLoadProgress(View view)
	{
		this.view = new WeakReference<View>(view);
		textView = new WeakReference<TextView>((TextView)view.findViewById(R.id.progress));
	}
	
	public void updateProgress(long planSize, long curSize)
	{
		int per =(int) (((float) curSize/(float) planSize) * 100);
		if(textView.get()!=null)
			textView.get().setText(per + "%");
	}
	
	public void updateProgress(int progress)
	{
		if(textView.get()!=null)
			textView.get().setText(progress + "%");
	}
	
	public void updateProgressComplete()
	{
		if(view.get() != null)
			view.get().setVisibility(View.GONE);
	}
	
	public void updateProgressBegian()
	{
		if(view.get() != null)
			view.get().setVisibility(View.VISIBLE);
	}

}
